from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-11-06 14:02:44.570786
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 06, Nov, 2022
Time: 14:02:53
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.8831
Nobs: 832.000 HQIC: -51.1981
Log likelihood: 10844.9 FPE: 4.78462e-23
AIC: -51.3941 Det(Omega_mle): 4.29684e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.297524 0.051033 5.830 0.000
L1.Burgenland 0.109475 0.034963 3.131 0.002
L1.Kärnten -0.106407 0.018621 -5.714 0.000
L1.Niederösterreich 0.210201 0.073127 2.874 0.004
L1.Oberösterreich 0.100578 0.069645 1.444 0.149
L1.Salzburg 0.251043 0.037092 6.768 0.000
L1.Steiermark 0.036048 0.048673 0.741 0.459
L1.Tirol 0.106844 0.039417 2.711 0.007
L1.Vorarlberg -0.058973 0.033986 -1.735 0.083
L1.Wien 0.057982 0.062439 0.929 0.353
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.068300 0.105370 0.648 0.517
L1.Burgenland -0.031323 0.072190 -0.434 0.664
L1.Kärnten 0.047448 0.038449 1.234 0.217
L1.Niederösterreich -0.172916 0.150990 -1.145 0.252
L1.Oberösterreich 0.377818 0.143799 2.627 0.009
L1.Salzburg 0.288614 0.076586 3.768 0.000
L1.Steiermark 0.106553 0.100498 1.060 0.289
L1.Tirol 0.315787 0.081386 3.880 0.000
L1.Vorarlberg 0.023649 0.070172 0.337 0.736
L1.Wien -0.017365 0.128922 -0.135 0.893
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.194810 0.026350 7.393 0.000
L1.Burgenland 0.091945 0.018053 5.093 0.000
L1.Kärnten -0.008789 0.009615 -0.914 0.361
L1.Niederösterreich 0.266220 0.037759 7.051 0.000
L1.Oberösterreich 0.116504 0.035961 3.240 0.001
L1.Salzburg 0.051310 0.019152 2.679 0.007
L1.Steiermark 0.017215 0.025132 0.685 0.493
L1.Tirol 0.096914 0.020353 4.762 0.000
L1.Vorarlberg 0.057507 0.017548 3.277 0.001
L1.Wien 0.117421 0.032240 3.642 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105430 0.027022 3.902 0.000
L1.Burgenland 0.046755 0.018513 2.526 0.012
L1.Kärnten -0.017108 0.009860 -1.735 0.083
L1.Niederösterreich 0.195844 0.038721 5.058 0.000
L1.Oberösterreich 0.282150 0.036877 7.651 0.000
L1.Salzburg 0.119850 0.019640 6.102 0.000
L1.Steiermark 0.102440 0.025772 3.975 0.000
L1.Tirol 0.121870 0.020871 5.839 0.000
L1.Vorarlberg 0.069919 0.017995 3.885 0.000
L1.Wien -0.027879 0.033061 -0.843 0.399
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.127810 0.049058 2.605 0.009
L1.Burgenland -0.049451 0.033610 -1.471 0.141
L1.Kärnten -0.039838 0.017901 -2.225 0.026
L1.Niederösterreich 0.165523 0.070298 2.355 0.019
L1.Oberösterreich 0.139423 0.066950 2.082 0.037
L1.Salzburg 0.284602 0.035657 7.982 0.000
L1.Steiermark 0.034055 0.046790 0.728 0.467
L1.Tirol 0.163790 0.037892 4.323 0.000
L1.Vorarlberg 0.104975 0.032671 3.213 0.001
L1.Wien 0.070817 0.060024 1.180 0.238
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060515 0.038799 1.560 0.119
L1.Burgenland 0.041686 0.026582 1.568 0.117
L1.Kärnten 0.049732 0.014157 3.513 0.000
L1.Niederösterreich 0.227269 0.055597 4.088 0.000
L1.Oberösterreich 0.271822 0.052949 5.134 0.000
L1.Salzburg 0.057772 0.028200 2.049 0.040
L1.Steiermark -0.007856 0.037005 -0.212 0.832
L1.Tirol 0.155553 0.029968 5.191 0.000
L1.Vorarlberg 0.069079 0.025839 2.673 0.008
L1.Wien 0.075144 0.047471 1.583 0.113
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.179557 0.046488 3.862 0.000
L1.Burgenland -0.004479 0.031849 -0.141 0.888
L1.Kärnten -0.060830 0.016963 -3.586 0.000
L1.Niederösterreich -0.086330 0.066615 -1.296 0.195
L1.Oberösterreich 0.191943 0.063442 3.025 0.002
L1.Salzburg 0.058664 0.033789 1.736 0.083
L1.Steiermark 0.228870 0.044338 5.162 0.000
L1.Tirol 0.493757 0.035906 13.751 0.000
L1.Vorarlberg 0.049383 0.030959 1.595 0.111
L1.Wien -0.048706 0.056879 -0.856 0.392
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.156218 0.052946 2.951 0.003
L1.Burgenland -0.009769 0.036273 -0.269 0.788
L1.Kärnten 0.065053 0.019319 3.367 0.001
L1.Niederösterreich 0.201965 0.075868 2.662 0.008
L1.Oberösterreich -0.068567 0.072255 -0.949 0.343
L1.Salzburg 0.221871 0.038482 5.765 0.000
L1.Steiermark 0.114983 0.050497 2.277 0.023
L1.Tirol 0.082263 0.040894 2.012 0.044
L1.Vorarlberg 0.123885 0.035260 3.514 0.000
L1.Wien 0.113705 0.064780 1.755 0.079
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.352641 0.030998 11.376 0.000
L1.Burgenland 0.007953 0.021237 0.374 0.708
L1.Kärnten -0.024347 0.011311 -2.153 0.031
L1.Niederösterreich 0.226743 0.044418 5.105 0.000
L1.Oberösterreich 0.163318 0.042303 3.861 0.000
L1.Salzburg 0.051778 0.022530 2.298 0.022
L1.Steiermark -0.015596 0.029565 -0.528 0.598
L1.Tirol 0.113765 0.023942 4.752 0.000
L1.Vorarlberg 0.072993 0.020643 3.536 0.000
L1.Wien 0.051794 0.037926 1.366 0.172
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.043257 0.158113 0.191451 0.165124 0.129771 0.122615 0.068734 0.229634
Kärnten 0.043257 1.000000 0.001050 0.131935 0.044710 0.098810 0.428273 -0.051116 0.102650
Niederösterreich 0.158113 0.001050 1.000000 0.343274 0.164667 0.309184 0.124003 0.189445 0.336459
Oberösterreich 0.191451 0.131935 0.343274 1.000000 0.235203 0.339123 0.177697 0.178706 0.270825
Salzburg 0.165124 0.044710 0.164667 0.235203 1.000000 0.153033 0.143750 0.152358 0.140386
Steiermark 0.129771 0.098810 0.309184 0.339123 0.153033 1.000000 0.162329 0.147020 0.089445
Tirol 0.122615 0.428273 0.124003 0.177697 0.143750 0.162329 1.000000 0.120253 0.162160
Vorarlberg 0.068734 -0.051116 0.189445 0.178706 0.152358 0.147020 0.120253 1.000000 0.013736
Wien 0.229634 0.102650 0.336459 0.270825 0.140386 0.089445 0.162160 0.013736 1.000000